// 797. 所有可能的路径

/**
 * @param {number[][]} graph
 * @return {number[][]}
 */
var allPathsSourceTarget = function (graph) {
    let res = [],
        tmp = [];
    // 深度优先、回溯
    const dfs = (graph, cur) => {
        if (cur == graph.length - 1) {
            res.push(tmp.slice());
            return;
        }
        if (cur == 0) tmp.push(0);
        for (let g of graph[cur]) {
            tmp.push(g);
            dfs(graph, g);
            tmp.pop();
        }
    };
    dfs(graph, 0);
    return res;
};
